package com.yuda.campsite.controller;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.oss.OSS;
import com.aliyun.teaopenapi.models.Config;
import com.yuda.campsite.domain.*;
import com.yuda.campsite.dto.WorkForCampsiteParam;
import com.yuda.campsite.dto.ZhiDingZuoYeParams;
import com.yuda.campsite.service.IWorkForCampsiteServlce;
import com.yuda.campsite.service.WeiTiJiaoStudentService;
import com.yuda.campsite.service.WorkForQianDuanService;
import com.yuda.common.core.utils.file.OssFileUtils;
import com.yuda.common.core.utils.poi.ExcelUtil;
import com.yuda.common.core.web.domain.AjaxResult;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author: xiaohudie
 * @Date: 2021/12/7 17:04
 * @Version: 1.8
 */
@RestController
@RequestMapping("/ld")
@Slf4j
public class WorkForCampsiteController {
    @Resource
    private IWorkForCampsiteServlce workForCampsiteServlce;
    @Resource
    private OSS oss;
    @Resource
    private Client client;
    @Resource
    private WeiTiJiaoStudentService weiTiJiaoStudentService;
    @Resource
    private WorkForQianDuanService workForQianDuanService;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    @Resource
    private   OSS ossClientInter;
    @GetMapping("/testRedis")
    public void testRedis() throws InterruptedException {

        stringRedisTemplate.opsForSet().add("student_workids_:10001", "fafssgs", "dfasdfasdfsa", "adfsafdsadf");
        stringRedisTemplate.opsForSet().add("student_workids_:10001", "fafssgs2");
        stringRedisTemplate.opsForSet().remove("student_workids_:10001","fafssgs3");
        Thread.sleep(1000L);
        stringRedisTemplate.delete("student_workids_:10001");

        Set<String> members = stringRedisTemplate.opsForSet().members("student_workids_:10001");
        for (String member : members) {
            System.out.println(member);
        }
    }

    /**
     * 时间戳转化工具类
     */
    public static String timeStamp2Date(String seconds, String format) {
        if (seconds == null || seconds.isEmpty() || seconds.equals("null")) {
            return "";
        }
        if (format == null || format.isEmpty()) {
            format = "yyyy-MM-dd HH:mm:ss";
        }
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(new Date(Long.valueOf(seconds + "000")));
    }

    /**
     * 判断文件大小的公共接口
     */
    public static boolean checkFileSize(long len, int size, String unit) {
        double fileSize = 0;
        if ("B".equals(unit.toUpperCase())) {
            fileSize = (double) len;
        } else if ("K".equals(unit.toUpperCase())) {
            fileSize = (double) len / 1024;
        } else if ("M".equals(unit.toUpperCase())) {
            fileSize = (double) len / 1048576;
        } else if ("G".equals(unit.toUpperCase())) {
            fileSize = (double) len / 1073741824;
        }
        if (fileSize > size) {
            return false;
        }
        return true;
    }

    /**
     * 得到已评阅学生的列表
     */
    @GetMapping("/yipingyue")
    public Map<String, Object> ld1(WorkForCampsiteParam workForCampsiteParam) throws ParseException {
        workForCampsiteParam.setQisi((workForCampsiteParam.getQisi() - 1) * workForCampsiteParam.getOffset());
        List<WorkForCampsite> workForCampsites1 = workForCampsiteServlce.YiPingYue(workForCampsiteParam);
        /**然后来计算total*/
        workForCampsiteParam.setQisi(0);
        workForCampsiteParam.setOffset(10000);
        /**此时的WorForCampsite就是包含了他在未评阅的时候更新的作业编号
         * 就是work_num*/
        List<WorkForCampsite> workForCampsites = workForCampsiteServlce.YiPingYue(workForCampsiteParam);
        int size = workForCampsites.size();
        Map<String, Object> jsonObject = new HashMap<>(4);
        jsonObject.put("code", 200);
        jsonObject.put("msg", "查询成功");
        jsonObject.put("total", size);
        jsonObject.put("data", workForCampsites1);
        return jsonObject;

    }

    /**
     * 得到待评阅学生的列表
     */
    @GetMapping("/weipingyue")
    public Map<String, Object> weipingyue(WorkForCampsiteParam workForCampsiteParam) throws ParseException {
        workForCampsiteParam.setQisi((workForCampsiteParam.getQisi() - 1) * workForCampsiteParam.getOffset());
        List<WorkForCampsite> workForCampsites = workForCampsiteServlce.WeiPingYue(workForCampsiteParam);
        /**设置题号的头根据前段传过来的题号进行拼接*/
//        workForCampsiteParam.setStuWorkNum("0");
//        String title = "0" + workForCampsiteParam.getStuWorkNum();
//        Integer i = 1;
//        for (WorkForCampsite workForCampsite : workForCampsites) {
//            if (i < 10) {
//                workForCampsite.setWorkNum(title + "000" + i.toString());
//            }
//            if (i >= 10 && i < 100) {
//                workForCampsite.setWorkNum(title + "00" + i.toString());
//            }
//            if (i >= 100 && i < 1000) {
//                workForCampsite.setWorkNum(title + "0" + i.toString());
//            }
//            if (i >= 1000) {
//                workForCampsite.setWorkNum(title + i.toString());
//            }
//            i++;
//        }
        /**然后计算total*/
        workForCampsiteParam.setQisi(0);
        workForCampsiteParam.setOffset(10000);
        List<WorkForCampsite> workForCampsites1 = workForCampsiteServlce.WeiPingYue(workForCampsiteParam);
        int size = workForCampsites1.size();
        Map<String, Object> jsonObject = new HashMap<>(4);
        jsonObject.put("code", 200);
        jsonObject.put("msg", "查询成功");
        jsonObject.put("total", size);
        jsonObject.put("data", workForCampsites);
        return jsonObject;
    }

    /**
     * 得到未评阅学生的列表
     */
    @GetMapping("/weitijiao")
    public String weitijiao(WorkForCampsiteParam workForCampsiteParam) {
        workForCampsiteParam.setQisi((workForCampsiteParam.getQisi() - 1) * workForCampsiteParam.getOffset());
        List<WorkForCampsite> workForCampsites = workForCampsiteServlce.WeiTiJiao(workForCampsiteParam);
        /**现在来计算total*/
        workForCampsiteParam.setQisi(0);
        workForCampsiteParam.setOffset(10000);
        List<WorkForCampsite> workForCampsites1 = workForCampsiteServlce.WeiTiJiao(workForCampsiteParam);
        int size = workForCampsites1.size();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", 200);
        jsonObject.put("msg", "查询成功");
        jsonObject.put("total", size);
        jsonObject.put("data", workForCampsites);
        return jsonObject.toJSONString();
    }

    /**
     * 得到具体的学生作业
     */
    @GetMapping("/StuWork")
    public AjaxResult StuWork(WorkForCampsiteParam workForCampsiteParam) {
        WorkForCampsite workForCampsite = workForCampsiteServlce.ChaKanZuoYe(workForCampsiteParam);
        return AjaxResult.success("查询成功", workForCampsite);
    }

    /**
     * 评阅学生作业的接口
     */
    @PostMapping("/PingYueWork")
    public AjaxResult PingYueWork(WorkForCampsiteParam workForCampsiteParam) {
        Date date = new Date();
        workForCampsiteParam.setCreateTime(date);
        workForCampsiteParam.setUpdateTime(date);
        Integer integer = workForCampsiteServlce.TeaComment(workForCampsiteParam);
        return AjaxResult.success("评阅成功");
    }

    /**
     * 已评下一条接口
     */
    @GetMapping("/YiPingXiaYiTiao")
    public AjaxResult YiPingXiaYiTiao(WorkForCampsiteParam workForCampsiteParam) {
        /**设置一下查询所有列表*/
        workForCampsiteParam.setQisi(0);
        workForCampsiteParam.setOffset(10000);
        /**首先查找到这个列表当前的所有排序*/
        List<WorkForCampsite> workForCampsites = workForCampsiteServlce.WeiPingYue(workForCampsiteParam);
        /**创建一个存放所有学生UUID的集合(按照列表展示的顺序存放)*/
        List<String> stringList = new ArrayList<>();
        for (WorkForCampsite workForCampsite : workForCampsites) {
            stringList.add(workForCampsite.getUuid());
        }
        int i = stringList.indexOf(workForCampsiteParam.getUuid());
        /**判断这个用户是不是最后一个用户*/
        if (i < workForCampsites.size() - 1) {
            String s = stringList.get(i + 1);
            /**此时再次调用查找作业的方法*/
            workForCampsiteParam.setUuid(s);
            /**此时就得到了下一条的作业详情*/
            WorkForCampsite workForCampsite = workForCampsiteServlce.ChaKanZuoYe(workForCampsiteParam);
            return AjaxResult.success("查询下一条成功", workForCampsite);
        }
        if (i == workForCampsites.size() - 1) {
            return AjaxResult.error("评阅已结束");
        }
        return null;
    }

    /**
     * 回评接口
     */
    @PostMapping("/HuiPingWork")
    public AjaxResult HuiPingWork(WorkForCampsiteParam workForCampsiteParam) {
        Date date = new Date();
        workForCampsiteParam.setUpdateTime(date);
        Integer integer = workForCampsiteServlce.TeaCommentAgain(workForCampsiteParam);
        return AjaxResult.success("回评成功");
    }

    /**
     * 回评回显
     */
    @GetMapping("/HuiPingHuiXian")
    public AjaxResult HuiPingHuiXian(WorkForCampsiteParam workForCampsiteParam) {
        WorkForCampsite workForCampsite = workForCampsiteServlce.TeacherLd(workForCampsiteParam);
        return AjaxResult.success("查询成功", workForCampsite);
    }

    /**
     * 教师上传作业pdf,word,excel等文件，需要使用文件数组
     */
    @PostMapping("/UploadWork")
    public AjaxResult UploadWork(MultipartFile[] multipartFile) {
        /**用来装载这些url，多的之间使用,隔开*/
        List<String> list = new ArrayList<>();
        /**首先进行判空，老一套了*/
        if (multipartFile == null || multipartFile.length <= 0) {
            return AjaxResult.error("请不要上传空文件");
        }
        /**判断文件的大小不能超过十个*/
        if (multipartFile.length > 10) {
            return AjaxResult.error("请不要上传大于10个文件");
        }
        /**遍历文件进oss*/
        for (int i = 0; i < multipartFile.length; i++) {
            MultipartFile multipartFile1 = multipartFile[i];
            log.info("开始上传文件了");
            String originalFilename = multipartFile1.getOriginalFilename();
            String url;
            String s = UUID.randomUUID().toString().trim().replaceAll("-", "");
            String objectName = s + "work/" + originalFilename;
            String bucketName = "campiste-test";
            File file = new File("/mnt/upload/" + objectName);
            try {

                log.info("收到文件...");
                multipartFile1.transferTo(file);
                log.info("保存文件完毕...");
                ossClientInter.putObject(bucketName, objectName, file);
                url = "http://campiste.oss-cn-beijing.aliyuncs.com" + "/" + objectName;
                log.info("上传完毕...");
                list.add(url);
            } catch (Exception e) {
                e.printStackTrace();
                log.info("第" + i + "文件上传失败");
            } finally {
                if (file.exists()) {
                    file.delete();
                }
            }
        }
        /**将所得的URL集合转换为大的字符串*/
        String join = StringUtils.join(list, ",");
        return AjaxResult.success(join);
    }
    @Bean
    public static Client client() throws Exception {
        Config config = new Config()
                // 您的AccessKey ID
                .setAccessKeyId("LTAI4FeK52KgR5GHCC21EWmY")
                // 您的AccessKey Secret
                .setAccessKeySecret("1ydOmQ3gvDRe0pCrjVOK7lKsJLs0is");
        // 访问的域名
        config.endpoint = "dysmsapi.aliyuncs.com";
        return new Client(config);
    }

    @GetMapping("/SendMessage")
    public AjaxResult SendMessage() {
        SendSmsRequest sendSmsRequest = new SendSmsRequest();
        sendSmsRequest.setSignName("CAMPCENTER");
        sendSmsRequest.setPhoneNumbers("15077916636");
        sendSmsRequest.setTemplateCode("SMS_229638807");
        JSONObject finalJsonParameters = new JSONObject();
        finalJsonParameters.put("name", "大明星");
        finalJsonParameters.put("camp_name", "创造营2021");
        sendSmsRequest.setTemplateParam(finalJsonParameters.toJSONString());
        try {
            SendSmsResponse sendSmsResponse = client.sendSms(sendSmsRequest);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return AjaxResult.success("发送成功");
    }

    /**
     * 查看单个作业的未提交学生
     */
    @GetMapping("/NewWeiTiJiao")
    public String NewWeiTiJiao(WorkForCampsiteParam workForCampsiteParam) {
        workForCampsiteParam.setQisi((workForCampsiteParam.getQisi() - 1) * workForCampsiteParam.getOffset());
        List<WeiTiJiaoStudent> weiTiJiaoStudents = weiTiJiaoStudentService.WeiTiJiaoStudent(workForCampsiteParam);
        /**现在来计算TOTAL*/
        workForCampsiteParam.setQisi(0);
        workForCampsiteParam.setOffset(10000);
        List<WeiTiJiaoStudent> weiTiJiaoStudents1 = weiTiJiaoStudentService.WeiTiJiaoStudent(workForCampsiteParam);
        int size = weiTiJiaoStudents1.size();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("msg", "查询成功");
        jsonObject.put("total", size);
        jsonObject.put("data", weiTiJiaoStudents);
        jsonObject.put("code", 200);
        return jsonObject.toJSONString();
    }

    /**
     * 查看全部作业未提交的学生列表
     */
    @GetMapping("/XiaoHuDie")
    public String SbLH(WorkForCampsiteParam workForCampsiteParam) {
        workForCampsiteParam.setQisi((workForCampsiteParam.getQisi() - 1) * workForCampsiteParam.getOffset());
        List<WorkForCampsite> workForCampsites = workForCampsiteServlce.NewWeiTiJiao(workForCampsiteParam);
        /**现在来计算TOTAL*/
        workForCampsiteParam.setQisi(0);
        workForCampsiteParam.setOffset(10000);
        List<WorkForCampsite> weiTiJiaoStudents1 = workForCampsiteServlce.NewWeiTiJiao(workForCampsiteParam);
        int size = weiTiJiaoStudents1.size();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("msg", "查询成功");
        jsonObject.put("total", size);
        jsonObject.put("data", workForCampsites);
        jsonObject.put("code", 200);
        return jsonObject.toJSONString();
    }
    @SneakyThrows
    @PostMapping("/DaoBiao")
    public void DaoBiao(HttpServletResponse response,WorkForCampsiteParam workForCampsiteParam){
        workForCampsiteParam.setQisi(0);
        workForCampsiteParam.setOffset(10000);
        List<WorkForCampsite> workForCampsites = workForCampsiteServlce.WorkForCampsiteDaoBiao(workForCampsiteParam);
        ExcelUtil<WorkForCampsite> util = new ExcelUtil<WorkForCampsite>(WorkForCampsite.class);
        util.exportExcel(response, workForCampsites, "conf");

    }

    /**
     * 查看学校下面的学生列表接口
     */
    @GetMapping("/ChaKanXueXiaoLieBiao")
    public LinkedHashSet<Object> ChaKanXueXiaoLieBiao(@RequestParam(value = "campsiteId", required = true) String campsiteId,
                                                      @RequestParam(value = "workId") String workId) {
        /**因为是插入操作较多，所以使用LinkedHashMap*/
        /**首先查出该营地的所有学校列表(唯一的)*/
        //List<String> stringList = workForCampsiteServlce.ChaXunSchool(campsiteId);
        /**查出所有符合条件的对象
         * 其实也就是一样的
         * 只是根据题目ID来判断一下需要展 示什么*/
        List<WorkForQianDuan> workForQianDuans = workForQianDuanService.ChaXunStudentTrue(campsiteId);
        Map<String, List<WorkForQianDuan>> collect = workForQianDuans.stream().collect(Collectors.groupingBy(WorkForQianDuan::getSchool));
        LinkedHashSet<Object> set = new LinkedHashSet<>();
        for (String s : collect.keySet()) {
            HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
            objectObjectHashMap.put("uuid", s);
            objectObjectHashMap.put("name", s);
            objectObjectHashMap.put("children", collect.get(s));
            set.add(objectObjectHashMap);
        }
        return set;
    }

    /**前端回显使用的方法*/

    @GetMapping("/QianDuanHuiXian")
    public AjaxResult QianDuanHuiXian(@RequestParam("campsiteId") String campsiteId,
                                      @RequestParam("workId") String workId){
        List<String> list = workForQianDuanService.XuanZheHuiXian(campsiteId, workId);
        return AjaxResult.success("已经选择过的人的uuid为:",list);
    }
    /**
     * 指定学生做那个作业的方法
     */
    @PostMapping("/ZhiDingZuoYe")
    public synchronized AjaxResult  ZhiDingZuoYe(@RequestBody ZhiDingZuoYeParams zhiDingZuoYeParams) {
        /**首先所有的操作都是一条一条进行的，因为每个学生的作业情况不一样，不能使用批量操作
         * 先查出这个学生原来的workId,默认是0，第一次直接uodate为新的，
         * 如果不为0，则直接加,然后update*/
        /**第一步将这些学生放入redis中，肯定是先定义key,再进行比较，第一次肯定是null，比较之后再进行放入redis中*/
        /**首先判断redis里面是否有这个key*/
        /**进行去重操作，第一次是null和他去重获得的是*/

        String[] split1 = zhiDingZuoYeParams.getStudentIdList().split(",");

        Set<String> members = stringRedisTemplate.opsForSet().members("student_id_zuoye:"+zhiDingZuoYeParams.getWorkId());
        List<String> Redislist =new ArrayList<>();
        if (members!=null) {
            for (String member : members) {
                Redislist.add(member);
            }
        }
        if (members==null){
            Redislist=null;
        }
        List<String> StudentList = new ArrayList<>();
        for (String s : split1) {
            StudentList.add(s);
        }
        /**StudentList 和 Redislist 去重是新加的需要做这次作业的学生
         * 需要判空，如果为空则去重就是studentList*/
        List<String> subtract =new ArrayList<>();
        if (Redislist!=null) {
             subtract = getSubtract(StudentList, Redislist);
        }else {
            subtract = StudentList;
        }
        /**subtract集合是需要新加学生做作业的人数集合(第一次指定作业的人就直接用原来的方法)*/
        if (subtract!=null && subtract.size()>0) {
            for (String s : subtract) {
                String s1 = workForQianDuanService.XueShengWorkId(s, zhiDingZuoYeParams.getCampsiteId());
                if ( s1!=null && s1.equals("0")) {
                    /**如果等于0，则说明这个学生是第一次被指定作业,直接update*/
                    workForQianDuanService.ZhiDingZuoYe(zhiDingZuoYeParams.getWorkId(), s, zhiDingZuoYeParams.getCampsiteId());
                } else {
                    /**说明这个学生是第二次被指定作业了(这里指的是其他作业不是取消这次作业),直接加","*/
                    String s2 = s1 + "," + zhiDingZuoYeParams.getWorkId();
                    workForQianDuanService.ZhiDingZuoYe(s2, s, zhiDingZuoYeParams.getCampsiteId());
                }
            }
        }
        /**RedisList 和 StudentList 去重是需要取消做这次作业的学生集合
         * 同样需要判空如果为空则去重就是null，啥也不用干*/
        List<String> subtract1 =new ArrayList<>();
        if (Redislist!=null) {
             subtract1 = getSubtract(Redislist, StudentList);
             if(subtract1!=null && subtract1.size()>0){
            /**进行判断该学生是否是只有这一题还是有多题*/
            for (String s : subtract1) {
             /**定义一个修改成功后的变量*/
             Integer a ;
                /**取出这些学生原来的work_id*/
                String s1 = workForQianDuanService.ChaXunZuoYeId(s, zhiDingZuoYeParams.getCampsiteId());
                /**说明这个学生目前只有这一题*/
                if (s1.contains(zhiDingZuoYeParams.getWorkId()) && !s1.contains(",")) {
                    /**直接update为0*/
                     a = workForQianDuanService.ZhiDingZuoYe("0", s, zhiDingZuoYeParams.getCampsiteId());
                }/**说明这个学生至少有两题*/
                else {
                    String[] split = s1.split(",");
                    List<String> list = new ArrayList<>();
                    for (String s2 : split) {
                        if (!s2.equals(zhiDingZuoYeParams.getWorkId())) {
                            list.add(s2);
                        }
                    }
                    String collect = list.stream().collect(Collectors.joining(","));
                    /**现在才能直接update进数据库*/
                    a = workForQianDuanService.ZhiDingZuoYe(collect, s, zhiDingZuoYeParams.getCampsiteId());
                    /**从redis中删除这些取消做作业的学生*/
                   /* stringRedisTemplate.opsForSet().remove("student_id_zuoye:" + workId, s);*/
                }
                /**如果修改成功才能删除redis中的value*/
                if (a==1){
                     stringRedisTemplate.opsForSet().remove("student_id_zuoye:" + zhiDingZuoYeParams.getWorkId(), s);
                }
            }
            }
        }
        /**最后将这个传过来的集合放入redis里面(这个只有第一次指定过后使用)*/
        for (String s : split1) {
            stringRedisTemplate.opsForSet().add("student_id_zuoye:" + zhiDingZuoYeParams.getWorkId(), s);
        }
        return AjaxResult.success("指定成功");
    }
    //获取两个集合的差集 list1 - 交集
    public static List<String> getSubtract(List<String> list1,List<String> list2){
        List<String> subtract = (List<String>) CollectionUtils.subtract(list1, list2);
        return subtract;
    }
    /**
     * 得到数据的方法
     */
    @GetMapping("/WorkShuJu")
    public AjaxResult WorkShuJu(@RequestParam("workId") String workId) {
        /**首先new一个返回给前端的对象出来*/
        WorkMessage workMessage = new WorkMessage();
        /**查看需要哪些学生做的总数量*/
        Integer integer = workForQianDuanService.WorkZhongShuLiang(workId);
        /**查看所有提交过的学生数量*/
        Integer integer1 = workForQianDuanService.YiTiJiaoShuLiang(workId);
        /**相减就是未提交数量*/
        Integer a = integer - integer1;
        /**已提交未评分数量*/
        Integer integer2 = workForQianDuanService.WeiPingFen(workId);
        /**已评分数量*/
        Integer integer3 = workForQianDuanService.YiPingFen(workId);
        workMessage.setZhongShuLiang(integer);
        workMessage.setWeiTiJiao(a);
        workMessage.setWeiPingFen(integer2);
        workMessage.setYiPingFen(integer3);
        return AjaxResult.success("查询成功", workMessage);
    }

    /**
     * 得到待评阅学生的列表
     */
    @GetMapping("/weipingyue2")
    public Map<String, Object> weipingyue2(WorkForCampsiteParam workForCampsiteParam) throws ParseException {
       /**先把前端传过来的qisi  和 offset 存起来*/
        Integer qisi = workForCampsiteParam.getQisi();
        Integer offset = workForCampsiteParam.getOffset();
//
//        /**首先查出在这个请求发生的时候符合条件的各个学生，将他们update
//         * 所以这时候的qisi 和  offset 应该设置为0到1000
//         * 这样做的目的是为了防止用户直接点击第2也或者第3页从而造成update的第一个指出错*/
//  //       workForCampsiteParam.setQisi((workForCampsiteParam.getQisi() - 1) * workForCampsiteParam.getOffset());
//     workForCampsiteParam.setQisi(0);
//     workForCampsiteParam.setOffset(1000);
//        /**这些是第一次得到的提交的学生是按照提交作业的顺序排好序的*/
//        List<WorkForCampsite> workForCampsites = workForCampsiteServlce.WeiPingYue(workForCampsiteParam);
//        /**需要用到redis来存这个每次请求都依赖与上一次的请求而改变的数据
//         * 就是存用到的i,i是随着update的人的次数变化着的*/
//       // Set<String> members = stringRedisTemplate.opsForSet().members("work_id_zuoye:"+workForCampsiteParam.getStuWorkNum());
//        String s = stringRedisTemplate.opsForValue().get("work_id" + workForCampsiteParam.getCampWorkTid());
//        /**还需要维护一个已经update过的学生uuid集合
//         * 直接取，第一次为null*/
//        Set<String> members = stringRedisTemplate.opsForSet().members("student_uuid"+workForCampsiteParam.getCampWorkTid());
//        /**这个集合是从redis中取的uuid*/
//        List<String> listRedis =new ArrayList<>();
//        for (String member : members) {
//            listRedis.add(member);
//        }
//        /**这个集合是存这次请求从数据库中查出来的uuid*/
//        List<String> listMysql =new ArrayList<>();
//        for (WorkForCampsite workForCampsite : workForCampsites) {
//            listMysql.add(workForCampsite.getUuid());
//        }
//        /**用来存需要update的学生uuid*/
//        List<String> listUpdate  =new ArrayList<>();
//
//        if (listRedis==null){
//            listUpdate = listMysql;
//        }else {
//            /**使用从数据库查出来的uuid集合与redis中存的uuid取差集就是本次需要update的学生*/
//            listUpdate = getSubtract(listMysql, listRedis);
//            /**这个时候就只update这些集合里 面的数据*/
//        }
//        Integer i =0 ;
//        if (s==null){
//             i =1;
//        }else {
//            i = Integer.valueOf(s);
//        }
//        if (listUpdate!=null){
//        /**现在开始update题号*/
//        for (String s1 : listUpdate) {
//            workForCampsiteServlce.ZhiDingZuoYeBianHao(String.valueOf(i),s1,workForCampsiteParam.getCampWorkTid());
//           i++;
//         /**再把这次update过的数据放入redis中，表明这些人下次查出来不需要再次update了*/
//         stringRedisTemplate.opsForSet().add("student_uuid"+workForCampsiteParam.getCampWorkTid(),s1);
//        }
//        }
//        /**再把这次目前的i存入redis中*/
//        stringRedisTemplate.opsForValue().set("work_id" + workForCampsiteParam.getCampWorkTid(), String.valueOf(i));
       /**现在再来查询就可以直接查出他的workNum(作业编号)
        * 还是带分页的*/
        workForCampsiteParam.setQisi((qisi - 1) * offset);
        workForCampsiteParam.setOffset(offset);
        List<WorkForCampsite> workForCampsites1 = workForCampsiteServlce.WeiPingYue(workForCampsiteParam);
       /* workForCampsiteParam.setQisi(0);
        workForCampsiteParam.setOffset(10000);
        List<WorkForCampsite> workForCampsites2 = workForCampsiteServlce.WeiPingYue(workForCampsiteParam);*/
        /**此时的这个size正是这次请求需要的size*/
        int size =  workForCampsiteServlce.weiPingYueCount(workForCampsiteParam);
//        int size = workForCampsites.size();
        Map<String, Object> jsonObject = new HashMap<>(4);
        jsonObject.put("code", 200);
        jsonObject.put("msg", "查询成功");
        jsonObject.put("total", size);
        jsonObject.put("data", workForCampsites1);

       return jsonObject;
    }
}

